package com.hongyuan.sellcoach.ui.member.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.sellcoach.R;
import com.hongyuan.sellcoach.base.AppViewModelFactory;
import com.hongyuan.sellcoach.base.CustomActivity;
import com.hongyuan.sellcoach.data.Constants;
import com.hongyuan.sellcoach.databinding.ActivityMemberFilterBinding;
import com.hongyuan.sellcoach.ui.member.beans.FilterBeans;
import com.hongyuan.sellcoach.ui.member.view_mode.MemberFilterViewModel;
import com.hongyuan.sellcoach.utils.CustomDialog;
import me.tatarka.bindingcollectionadapter2.BR;

public class MemberFilterActivity extends CustomActivity<ActivityMemberFilterBinding, MemberFilterViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_member_filter;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MemberFilterViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(MemberFilterViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        binding.comBack.setOnClickListener(view -> finish());
        setOnRefresh(binding.refresh,REFRESH_0X4);

        binding.editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                viewModel.filter.get().setNum(editable.toString().trim());
                //清除下，不然有问题
                binding.minNum.clearCheck();
                viewModel.filter.notifyChange();
            }
        });

    }

    @Override
    public void initData() {
        super.initData();

        FilterBeans filterBeans = (FilterBeans) getBundle().getSerializable("filterBean");
        viewModel.filter.set(filterBeans);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

        viewModel.uc.resetCheck.observe(this,aVoid -> {
            binding.memberStatus.clearCheck();
            binding.memberSex.clearCheck();
            binding.minNum.clearCheck();
            binding.editText.setText("");
        });
    }

}
